
export type ReviveRule = {
    Disabled?: boolean;
    disabled?: boolean;
    Arguments?: unknown[];
    arguments?: unknown[];
};

export const getRuleDisabled = (rule?: ReviveRule): boolean => {
    if (rule == undefined) {
        return false;
    }
    if (rule.Disabled !== undefined) {
        return rule.Disabled;
    }
    if (rule.disabled !== undefined) {
        return rule.disabled;
    }
    return false;
}

export const setRuleDisabled = (rule: ReviveRule, val: boolean) => {
    if (rule == undefined) {
        return;
    }
    if (rule.Disabled !== undefined) {
        rule.Disabled = val;
        return;
    }
    rule.disabled = val;
}

export const getArguments = (rule?: ReviveRule): (unknown[] | undefined) => {
    if (rule == undefined) {
        return undefined;
    }
    if (rule.Arguments !== undefined) {
        return rule.Arguments;
    }
    if (rule.arguments !== undefined) {
        return rule.arguments;
    }
    return undefined;
}

export const setArguments = (rule: ReviveRule, val: unknown[]) => {
    if (rule == undefined) {
        return;
    }
    if (rule.Arguments !== undefined) {
        rule.Arguments = val;
        return;
    }
    rule.arguments = val;
};

export interface ReviveRuleMap {
    "add-constant"?: ReviveRule;
    "argument-limit"?: ReviveRule;
    "atomic"?: ReviveRule;
    "bare-return"?: ReviveRule;
    "banned-characters"?: ReviveRule;
    "blank-imports"?: ReviveRule;
    "bool-literal-in-expr"?: ReviveRule;
    "call-to-gc"?: ReviveRule;
    "confusing-naming"?: ReviveRule;
    "comment-spacings"?: ReviveRule;
    "confusing-results"?: ReviveRule;
    "cognitive-complexity"?: ReviveRule;
    "constant-logical-expr"?: ReviveRule;
    "context-as-argument"?: ReviveRule;
    "context-keys-type"?: ReviveRule;
    "cyclomatic"?: ReviveRule;
    "datarace"?: ReviveRule;
    "deep-exit"?: ReviveRule;
    "defer"?: ReviveRule;
    "dot-imports"?: ReviveRule;
    "duplicated-imports"?: ReviveRule;
    "early-return"?: ReviveRule;
    "empty-block"?: ReviveRule;
    "empty-lines"?: ReviveRule;
    "error-naming"?: ReviveRule;
    "error-return"?: ReviveRule;
    "error-strings"?: ReviveRule;
    "errorf"?: ReviveRule;
    "exported"?: ReviveRule;
    "file-header"?: ReviveRule;
    "flag-parameter"?: ReviveRule;
    "function-result-limit"?: ReviveRule;
    "function-length"?: ReviveRule;
    "get-return"?: ReviveRule;
    "identical-branches"?: ReviveRule;
    "if-return"?: ReviveRule;
    "increment-decrement"?: ReviveRule;
    "indent-error-flow"?: ReviveRule;
    "imports-blacklist"?: ReviveRule;
    "import-shadowing"?: ReviveRule;
    "line-length-limit"?: ReviveRule;
    "max-public-structs"?: ReviveRule;
    "modifies-parameter"?: ReviveRule;
    "modifies-value-receiver"?: ReviveRule;
    "nested-structs"?: ReviveRule;
    "optimize-operands-order"?: ReviveRule;
    "package-comments"?: ReviveRule;
    "range"?: ReviveRule;
    "range-val-in-closure"?: ReviveRule;
    "range-val-address"?: ReviveRule;
    "receiver-naming"?: ReviveRule;
    "redefines-builtin-id"?: ReviveRule;
    "string-of-int"?: ReviveRule;
    "struct-tag"?: ReviveRule;
    "string-format"?: ReviveRule;
    "superfluous-else"?: ReviveRule;
    "time-equal"?: ReviveRule;
    "time-naming"?: ReviveRule;
    "var-naming"?: ReviveRule;
    "var-declaration"?: ReviveRule;
    "unconditional-recursion"?: ReviveRule;
    "unexported-naming"?: ReviveRule;
    "unexported-return"?: ReviveRule;
    "unhandled-error"?: ReviveRule;
    "unnecessary-stmt"?: ReviveRule;
    "unreachable-code"?: ReviveRule;
    "unused-parameter"?: ReviveRule;
    "unused-receiver"?: ReviveRule;
    "use-any"?: ReviveRule;
    "useless-break"?: ReviveRule;
    "waitgroup-by-value"?: ReviveRule;
}

export interface ReviveConfig {
    //是否忽略GENERATED头的文件
    ignoreGeneratedHeader?: boolean;
    //Sets the default failure confidence. This means that linting errors with less than 0.8 confidence will be ignored.
    confidence?: number;
    //打开所有配置
    enableAllRules?: boolean;
    errorCode?: number;
    severity?: string;
    warningCode?: number;
    rule: ReviveRuleMap;
}

export const ReviveRuleKeyList: (keyof ReviveRuleMap)[] = [
    "add-constant",
    "argument-limit",
    "atomic",
    "bare-return",
    "banned-characters",
    "blank-imports",
    "bool-literal-in-expr",
    "call-to-gc",
    "confusing-naming",
    "comment-spacings",
    "confusing-results",
    "cognitive-complexity",
    "constant-logical-expr",
    "context-as-argument",
    "context-keys-type",
    "cyclomatic",
    "datarace",
    "deep-exit",
    "defer",
    "dot-imports",
    "duplicated-imports",
    "early-return",
    "empty-block",
    "empty-lines",
    "error-naming",
    "error-return",
    "error-strings",
    "errorf",
    "exported",
    "file-header",
    "flag-parameter",
    "function-result-limit",
    "function-length",
    "get-return",
    "identical-branches",
    "if-return",
    "increment-decrement",
    "indent-error-flow",
    "imports-blacklist",
    "import-shadowing",
    "line-length-limit",
    "max-public-structs",
    "modifies-parameter",
    "modifies-value-receiver",
    "nested-structs",
    "optimize-operands-order",
    "package-comments",
    "range",
    "range-val-in-closure",
    "range-val-address",
    "receiver-naming",
    "redefines-builtin-id",
    "string-of-int",
    "struct-tag",
    "string-format",
    "superfluous-else",
    "time-equal",
    "time-naming",
    "var-naming",
    "var-declaration",
    "unconditional-recursion",
    "unexported-naming",
    "unexported-return",
    "unhandled-error",
    "unnecessary-stmt",
    "unreachable-code",
    "unused-parameter",
    "unused-receiver",
    "use-any",
    "useless-break",
    "waitgroup-by-value",
];

export const RecommendRuleKeyList: (keyof ReviveRuleMap)[] = [
    "blank-imports",
    "context-as-argument",
    "context-keys-type",
    "dot-imports",
    "error-return",
    "error-strings",
    "error-naming",
    "exported",
    "if-return",
    "increment-decrement",
    "var-naming",
    "var-declaration",
    "package-comments",
    "range",
    "receiver-naming",
    "time-naming",
    "unexported-return",
    "indent-error-flow",
    "errorf",
    "empty-block",
    "superfluous-else",
    "unused-parameter",
    "unreachable-code",
    "redefines-builtin-id",    
];